//
//  SwitchSettingCellData.m
//  18Birdies
//
//  Created by Lc on 15/4/28.
//  Copyright (c) 2015年 Lc. All rights reserved.
//

#import "LcFoundation.h"
#import "SwitchSettingCell.h"
#import "SwitchSettingCellData.h"

@implementation SwitchSettingCellData

+ (SwitchSettingCellData*)cellDataWithTitle:(NSString*)title
                                titleLcFont:(LcFont*)titleLcFont
                                   delegate:
                                       (id<SwitchSettingDelegate>)delegate {
  LC_CHECK_NOT_EMPTY(title);
  return [self cellDataWithTitle:title
                        subtitle:nil
                     titleLcFont:titleLcFont
                        delegate:delegate];
}

+ (SwitchSettingCellData*)cellDataWithTitle:(NSString*)title
                                   subtitle:(NSString*)subtitle
                                titleLcFont:(LcFont*)titleLcFont
                                   delegate:
                                       (id<SwitchSettingDelegate>)delegate {
  LC_CHECK_NOT_EMPTY(title);
  return [self cellDataWithTitle:title
                        subtitle:subtitle
                 linesOfSubtitle:1
                     titleLcFont:titleLcFont
                        delegate:delegate];
}

+ (SwitchSettingCellData*)cellDataWithTitle:(NSString*)title
                                   subtitle:(NSString*)subtitle
                            linesOfSubtitle:(int)linesOfSubtitle
                                titleLcFont:(LcFont*)titleLcFont
                                   delegate:
                                       (id<SwitchSettingDelegate>)delegate {
  LC_CHECK_NOT_EMPTY(title);
  LC_CHECK_TRUE(linesOfSubtitle >= 1);
  SwitchSettingCellData* cellData = [[self alloc] init];
  cellData->_title = title.copy;
  cellData->_subtitle = subtitle.copy;
  cellData->_linesOfSubtitle = linesOfSubtitle;
  cellData->_titleLcFont = titleLcFont;
  cellData.delegate = delegate;
  cellData.clickable = NO;
  cellData.cellHeight = 44 + (linesOfSubtitle - 1) * 15;
  return cellData;
}

- (Class)cellClazz {
  return SwitchSettingCell.class;
}

- (NSString*)nibName {
  return @"SwitchSettingCell";
}

- (void)refreshCell:(SwitchSettingCell*)cell {
  [super refreshCell:cell];
  cell.subtitleLabel.numberOfLines = self.linesOfSubtitle;
  if (self.subtitle.length == 0) {
    cell.titleLabel.hidden = NO;
    cell.titleLabel.text = self.title;
    cell.title2Label.hidden = YES;
    cell.subtitleLabel.hidden = YES;
    [cell.titleLabel setLcFont:self.titleLcFont];
  } else {
    cell.titleLabel.hidden = YES;
    cell.title2Label.text = self.title;
    cell.title2Label.hidden = NO;
    cell.subtitleLabel.text = self.subtitle;
    cell.subtitleLabel.hidden = NO;
  }
  cell.switchButton.on = self.switchOn;
}

@end
